﻿using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TSL_Tools.XMLTools;
using System.Xml;

namespace ReportingAppConfig
{
    public class MachineAliases
    {
        #region -- Public Properties ----------------------------------------------------
        public Dictionary<string, string> machineAliasSet { get; private set; }
        public Dictionary<string, string> machineListAliasSet { get; private set; }
        #endregion

        #region -- Private Properties ---------------------------------------------------
        #endregion

        #region -- Constructors ---------------------------------------------------------
        public MachineAliases() 
        {
            machineAliasSet = new Dictionary<string, string>();
            machineListAliasSet = new Dictionary<string, string>();
        }
        #endregion

        #region -- Public Methods -------------------------------------------------------
        /// <summary>
        /// Used to load the config user settings into the  <see cref="AppConfiguration"/> class settings
        /// </summary>
        public void GetConfigValues(XmlDocument xDoc)
        {
            GetSingleMachineAliases(xDoc);
            GetMachineListAliases(xDoc);
        }

        /// <summary>
        /// Used to set the <see cref="AppConfiguration"/> class settings back into the config user settings file and then to save them.
        /// </summary>
        public void SaveConfigValues(XmlDocument xDoc)
        {
        }
        #endregion

        #region -- Private Methods ------------------------------------------------------
        private void GetSingleMachineAliases(XmlDocument xDoc)
        {
            XmlNode xNode = xDoc.SelectSingleNode("Configuration/MachineAliases/MachineAliasSet[@Default]");
            {
                foreach (XmlNode xChild in xNode.SelectNodes("Alias"))
                {
                    machineAliasSet.Add(
                        XmlHelper.GetXmlAttributeValue(xChild, "name", ""),
                        XmlHelper.GetXmlAttributeValue(xChild, "machine", ""));
                }
            }
        }

        private void GetMachineListAliases(XmlDocument xDoc)
        {
            XmlNode xNode = xDoc.SelectSingleNode("Configuration/MachineAliases/MachineListAliasSet[@Default]");
            {
                foreach (XmlNode xChild in xNode.SelectNodes("Alias"))
                {
                    machineListAliasSet.Add(
                        XmlHelper.GetXmlAttributeValue(xChild, "name", ""),
                        XmlHelper.GetXmlAttributeValue(xChild, "machineList", ""));
                }
            }
        }
        #endregion
    }
}
